package com.gobo.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gobo.commonutils.JwtUtils;
import com.gobo.commonutils.R;
import com.gobo.eduservice.pojo.EduCourse;
import com.gobo.eduservice.pojo.EduTeacher;
import com.gobo.eduservice.pojo.front.FrontCourseQuery;
import com.gobo.eduservice.service.EduCourseService;
import com.gobo.servicebase.handler.exception.pojo.GoboException;
import com.gobo.servicebase.vo.CourseInfoFormVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/front/course")
public class FrontCourseController {

    @Autowired
    private EduCourseService courseService;

    @PostMapping("/page/{current}/{size}")
    public R getCoursePageList(@PathVariable long current,@PathVariable long size,
                                @RequestBody(required = false) FrontCourseQuery courseQuery){
        Page<EduCourse> page = new Page<>(current,size);
        Map<String,Object> map =  courseService.getFrontCourseByCourseCourseQuery(page,courseQuery);
        return R.ok().data(map);
    }

    //获取课程详情(包含课程)
    @GetMapping("/info/{id}")
    public R getCourseInfo(@PathVariable String id, HttpServletRequest request){
        String memberId = JwtUtils.getMemberIdByJwtToken(request);
        if (StringUtils.isEmpty(memberId)){
            throw new GoboException(30001,"用户未登录");
        }
        return courseService.getFrontCourseInfoById(id,memberId);
    }

    //获取课程详情(包含课程) 返回common包下的 service_base中的CourseInfoFromVo对象
    @PostMapping("/info/{id}")
    public CourseInfoFormVo getCommonCourseInfoFormVo(@PathVariable String id){
        return courseService.getCommonCourseInfoFormVo(id);
    }




}
